package com.smfx.yxt.view;

import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.smfx.yxt.common.Const;
import com.smfx.yxt.model.TermInfo;
import com.smfx.yxt.wechat.utils.WechatGlobalMap;

public class TermView extends TermInfo {
	
	private static final long serialVersionUID = 2414849224346649L;
	
	//初中年级
	private Map<Integer, String> middleGradeMap;
	//高中年级
	private Map<Integer, String> highGradeMap;
	//毕业年
	private Integer finishYear;
	
	private Integer termKey;

	public Map<Integer, String> getMiddleGradeMap() {
		return middleGradeMap;
	}

	public void setMiddleGradeMap(Map<Integer, String> middleGradeMap) {
		this.middleGradeMap = middleGradeMap;
	}

	public Map<Integer, String> getHighGradeMap() {
		return highGradeMap;
	}

	public void setHighGradeMap(Map<Integer, String> highGradeMap) {
		this.highGradeMap = highGradeMap;
	}

	public static String getGradeName(Integer grade, Integer studentType) {
		if(grade == null || studentType == null){
			return "";
		}
		TermView view = (TermView) WechatGlobalMap.get(Const.CACHE_TERM).getValue();
		String gradeName = null;
		if(studentType == 1) {
			gradeName = view.getMiddleGradeMap().get(grade);
		}else {
			gradeName = view.getHighGradeMap().get(grade);
		}
		if(StringUtils.isBlank(gradeName)){
			if(studentType == 1) return "初中" + grade + "届";
			return "高中" + grade + "届";
		}
		return gradeName;
	}
	
	public static String getTeachrGradeName(Integer grade, Integer studentType) {
		TermView view = (TermView) WechatGlobalMap.get(Const.CACHE_TERM).getValue();
		String gradeName = null;
		if(studentType == 1) {
			gradeName = view.getMiddleGradeMap().get(grade);
		}else {
			gradeName = view.getHighGradeMap().get(grade);
		}
		if(StringUtils.isBlank(gradeName)) return "无";
		return gradeName;
	}
	
	public Integer getFinishYear() {
		if(finishYear == null) {
			init();
		}
		return finishYear;
	}

	public void setFinishYear(Integer finishYear) {
		this.finishYear = finishYear;
	}

	public Integer getTermKey() {
		return termKey;
	}

	public void setTermKey(Integer termKey) {
		this.termKey = termKey;
	}
	public void init() {
		String termName = super.getTermName();
		Integer grade = Integer.valueOf(termName.substring(0, termName.indexOf("-")));
		this.termKey = grade;
		this.finishYear = grade - 3;
		if(this.middleGradeMap == null) {
			Map<Integer, String> map = new LinkedHashMap<>();
			map.put(grade, "初一");
			map.put(grade.intValue() - 1, "初二");
			map.put(grade.intValue() - 2, "初三");
			this.middleGradeMap = map;
		}
		if(this.highGradeMap == null) {
			Map<Integer, String> map = new LinkedHashMap<>();
			map.put(grade, "高一");
			map.put(grade.intValue() - 1, "高二");
			map.put(grade.intValue() - 2, "高三");
			this.highGradeMap = map;
		}
	}
	
}
